// pages/akxiche/akxiche.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid: '',
    USER_ASSETS_TICKET_PHONE: '',
    wangdian: [
      // {
      //   id: 1,
      //   wangname: "县营业网点"
      // },
      {
        id: 1,
        wangname: "商州",
        wangnamea: [{
            id: 2,
            wangname: "商州西新街邮局"
          },
          {
            id: 3,
            wangname: "商州名人街邮局"
          },
          {
            id: 4,
            wangname: "商州东郊校邮局"
          },
          {
            id: 5,
            wangname: "商州夜村邮局"
          },
          {
            id: 6,
            wangname: "商州白杨店邮局"
          },
          {
            id: 7,
            wangname: "商州杨斜邮局"
          },
          {
            id: 8,
            wangname: "商州金陵寺邮局"
          },
          {
            id: 9,
            wangname: "商州黑山邮局"
          },
          {
            id: 10,
            wangname: "商州板桥邮局"
          },
          {
            id: 11,
            wangname: "商州腰市邮局"
          },
          {
            id: 12,
            wangname: "商州大荆邮局"
          },
          {
            id: 13,
            wangname: "商州沙河子邮局"
          },
          {
            id: 14,
            wangname: "商州黑龙口邮局"
          },
        ],



      },

      {
        id: 15,
        wangname: "洛南",
        wangnamea: [{
            id: 16,
            wangname: "洛南新西街邮局"
          },
          {
            id: 16,
            wangname: "洛南石门邮局"
          },
          {
            id: 17,
            wangname: "洛南寺耳邮局"
          },
          {
            id: 18,
            wangname: "洛南石坡邮局"
          },
          {
            id: 19,
            wangname: "洛南巡检邮局"
          },
          {
            id: 20,
            wangname: "洛南灵口邮局"
          },
          {
            id: 21,
            wangname: "洛南三要邮局"
          },
          {
            id: 22,
            wangname: "洛南古城邮局"
          },
          {
            id: 23,
            wangname: "洛南景村邮局"
          },
          {
            id: 24,
            wangname: "洛南永丰邮局"
          },
          {
            id: 25,
            wangname: "洛南保安邮局"
          },
        ],
      },
      {
        id: 26,
        wangname: "丹凤",
        wangnamea: [{
            id: 26,
            wangname: "丹凤武关邮局"
          },
          {
            id: 27,
            wangname: "丹凤龙驹寨邮局"
          },
          {
            id: 28,
            wangname: "丹凤广场邮局"
          },
          {
            id: 29,
            wangname: "丹凤棣花邮局"
          },
          {
            id: 30,
            wangname: "丹凤竹林关邮局"
          },
          {
            id: 31,
            wangname: "丹凤商镇邮局"
          },
          {
            id: 32,
            wangname: "丹凤铁峪铺邮局"
          },
          {
            id: 33,
            wangname: "丹凤峦庄邮局"
          },
        ]
      },

      {
        id: 34,
        wangname: "商南",
        wangnamea: [{
            id: 34,
            wangname: "商南长新路邮局"
          },
          {
            id: 35,
            wangname: "商南湘河邮局"
          },
          {
            id: 36,
            wangname: "商南青山邮局"
          },
          {
            id: 37,
            wangname: "商南白玉邮局"
          },
          {
            id: 38,
            wangname: "商南富水邮局"
          },
          {
            id: 39,
            wangname: "商南赵川邮局"
          },
          {
            id: 40,
            wangname: "商南试马邮局"
          },
          {
            id: 41,
            wangname: "商南南街邮局"
          },
        ]
      },
      {
        id: 42,
        wangname: "山阳",
        wangnamea: [{
            id: 42,
            wangname: "山阳城关镇邮局"
          },
          {
            id: 43,
            wangname: "山阳户垣邮局"
          },
          {
            id: 44,
            wangname: "山阳小河邮局"
          },
          {
            id: 67,
            wangname: "山阳丰阳邮局"
          },
          {
            id: 45,
            wangname: "山阳色河邮局"
          },
          {
            id: 46,
            wangname: "山阳宽坪邮局"
          },
          {
            id: 47,
            wangname: "山阳漫川邮局"
          },
          {
            id: 48,
            wangname: "山阳照川邮局"
          },
          {
            id: 49,
            wangname: "山阳中村邮局"
          },
          {
            id: 50,
            wangname: "山阳高坝邮局"
          },
        ]

      },
      {
        id: 51,
        wangname: "镇安",
        wangnamea: [{
            id: 51,
            wangname: "镇安云镇邮局"
          },
          {
            id: 52,
            wangname: "镇安青铜邮局"
          },
          {
            id: 53,
            wangname: "镇安柴坪邮局"
          },
          {
            id: 54,
            wangname: "镇安迎宾路邮局"
          },
          {
            id: 55,
            wangname: "镇安高峰邮局"
          },
          {
            id: 56,
            wangname: "镇安回龙邮局"
          },
          {
            id: 57,
            wangname: "镇安西口邮局"
          },
          {
            id: 58,
            wangname: "镇安米粮邮局"
          },
          {
            id: 59,
            wangname: "镇安大坪邮局"
          },
          {
            id: 60,
            wangname: "镇安永安路邮局"
          },
          {
            id: 61,
            wangname: "镇安永乐邮局"
          },
        ]
      },
      {
        id: 62,
        wangname: "柞水",
        wangnamea: [{
            id: 62,
            wangname: "柞水曹坪邮局"
          },
          {
            id: 63,
            wangname: "柞水凤镇邮局"
          },
          {
            id: 64,
            wangname: "柞水下梁邮局"
          },
          {
            id: 65,
            wangname: "柞水营盘邮局"
          },
          {
            id: 66,
            wangname: "柞水红岩寺邮局"
          },

          {
            id: 68,
            wangname: "柞水霍台邮局"
          },
          {
            id: 69,
            wangname: "柞水北关邮局"
          },
          {
            id: 70,
            wangname: "柞水乾佑街邮局"
          },
        ]
      },

    ], //网点名称
    sheng: [{
        shengnei: '省内'
      },
      {
        shengnei: '省外'
      },
    ],

    wangdians: true,
    wangdianx: true,
    wangdiany: true,
    POST_ADD: '',
    USER_ASSETS_TICKET_NAME: '',
    USER_ASSETS_TICKET: '',
    USER_ASSETS_TICKET_COUNTY: "",
    USER_ASSETS_TICKET_PROVINCE: '',
  },


  // var arr = [100,20,50,58,6,69,36,45,78,66,45]
  // if(arr.indexOf(66)==-1){
  //       console.log("不存在")
  // }else{
  //       console.log("存在,索引是：",arr.indexOf(66))
  // }



  aabb() {
    let that = this


    if (that.data.USER_ASSETS_TICKET_PHONE == '' || that.data.POST_ADD == '' || that.data.USER_ASSETS_TICKET_NAME == '' || that.data.USER_ASSETS_TICKET_PROVINCE == '' || that.data.USER_ASSETS_TICKET_COUNTY == '') {
      wx.showToast({
        title: '请完善信息！',
        icon: 'none',
        duration: 1500
      })
    } else {

      const shusp = this.data.wangdian
      console.log(shusp);
      for (var i = 0; i < shusp.length; i++) {

        if (shusp[i].wangname === this.data.POST_ADD) {
          console.log(88);
          console.log(this.data.POST_ADD);
          wx.showToast({
            title: '',
            icon: '',
            duration: 1
          })
          wx.request({
            url: app.globalData.interface+'/shangluoTicket/API_4801_TicketUserLogo',
            method: 'POST',
            data: {
              USER_ASSETS_TICKET_PHONE: that.data.USER_ASSETS_TICKET_PHONE,
              USER_ASSETS_TICKET_ADDRESS: that.data.POST_ADD,
              USER_ASSETS_TICKET_NAME: that.data.USER_ASSETS_TICKET_NAME,
              USER_ASSETS_TICKET_COUNTY: that.data.USER_ASSETS_TICKET_COUNTY,
              USER_ASSETS_TICKET_PROVINCE: that.data.USER_ASSETS_TICKET_PROVINCE,
              KEY: 'xianjgjKey9999',
              // L3code: '',
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            success: res => {
              console.log(res);
              console.log(res.data);
              that.setData({
                ressj: res.data
              })
    
              if (res.data.result == 'error') {
                wx.showModal({
                  title: '温馨提示',
                  content: res.data.data,
                  success: function (res) {
                    if (res.confirm) { //这里是点击了确定以后
                      console.log('用户点击确定')
                    } else { //这里是点击了取消以后
                      console.log('用户点击取消')
                    }
                  }
                })
              } else { //往领券跳转时跳转带数据
    
                wx.showModal({
                  title: '温馨提示',
                  content: res.data.data,
                  success: function (res) {
                    if (res.confirm) { //这里是点击了确定以后
                      console.log('用户点击确定')
                      // wx.navigateTo({
                      //   url: '../../pages/shangchepiaochou/shangchepiaochou?data=' + JSON.stringify(that.data.ressj)
                      // })

                      that.login_a()
 
                    } else { //这里是点击了取消以后
                      console.log('用户点击取消')
                      that.login_a()
                    }
                  }
                })
    
              }
            }
          })
          break;
        } else {
          wx.showToast({
            title: '小程序已更新,请重启小程序',
            icon: 'none',
            duration: 2000
          })
        }

      }
    }
  },



  //登录接口
  login_a:function () {
    wx.request({
      url: app.globalData.interface+'/shangluoTicket/API_4815_UserTicketLogo',
      //  url:'http://208tk78580.51mypc.cn/shanyouhui/API_1004_UserLogo', 
      method: 'POST',
      data: {
        USER_ASSETS_TICKET_PHONE: this.data.USER_ASSETS_TICKET_PHONE,
        USER_ASSETS_TICKET_NAME: this.data.USER_ASSETS_TICKET_NAME,
        KEY:'xianjgjKey9999',
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      // 611000121212521451
      success: res => {
        console.log(res);
        console.log(res.data);

        var value = res.data
        // console.log('****************' + value);
        this.setData({
          ressj: value
        })

        if (res.data.result == 'error') {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                console.log('用户点击确定')
              } else {//这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {//往领券跳转时跳转带数据
          wx.navigateTo({
          url: '../../pages/shangchepiaochou/shangchepiaochou?data=' + JSON.stringify(this.data.ressj)
         
          })
        }
      }
    })
    // }
  },























  // 省选择
  shengji() {
    this.setData({
      wangdians: false,
    })


  },
  xsheng(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.shengnei);


    this.setData({
      USER_ASSETS_TICKET_PROVINCE: e.currentTarget.dataset.item.shengnei,
      wangdians: true
    })
  },




  //网点选择
  wangji() {
    this.setData({
      wangdiany: false,
      USER_ASSETS_TICKET_COUNTY: '',
    })
  },

  xwang(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.wangname);
    console.log(e.currentTarget.dataset.item.wangnamea);

    this.setData({
      POST_ADD: e.currentTarget.dataset.item.wangname,
      USER_ASSETS_TICKET: e.currentTarget.dataset.item.wangnamea,
      wangdiany: true
    })
  },



  //县区选择
  xianqu() {
    if (this.data.POST_ADD == '') {
      wx.showToast({
        title: '请先选择县区！',
        icon: 'none',
        duration: 1500
      })

    } else {
      this.setData({
        wangdianx: false
      })
    }

  },

  xianquxuan(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.wangname);

    this.setData({
      USER_ASSETS_TICKET_COUNTY: e.currentTarget.dataset.item.wangname,
      wangdianx: true
    })
  },









  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    console.log(value);
    this.setData({
      mobile: value,
    })

    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
     
        duration: 1500
      })
      this.setData({
        USER_ASSETS_TICKET_PHONE: '',
        mobileFormat: false,
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        USER_ASSETS_TICKET_PHONE: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        USER_ASSETS_TICKET_PHONE: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      openid: app.globalData.openid
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})